<template>
  <div class="article-page">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item>面经后台</el-breadcrumb-item>
      <el-breadcrumb-item>面经管理</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card shadow="never" border="false">
      <template #header>
        <div class="header">
          <span>共 {{total}} 条记录</span>
          <el-button
            icon="el-icon-plus"
            size="small"
            type="primary"
            round>
            添加面经
          </el-button>
        </div>
      </template>
      <!-- :data表示表格所需的数据 ，必须是一个数组
      lable表示表头的文字
      prop表示这列所要渲染的数据的属性名
       -->
     <el-table
      :data="list"
      style="width=100%"
     >
     <el-table-column
     label="标题"
     prop="stem"
     width="400"
     ></el-table-column>
     <el-table-column
     label="作者"
     prop="creator"
     ></el-table-column>
     <el-table-column
     label="点赞"
     prop="likeCount"
     ></el-table-column>
     <el-table-column
     label="浏览数"
     prop="views"
     ></el-table-column>
     <el-table-column
     label="更新时间"
     prop="createdAt"
     ></el-table-column>
     <el-table-column
     label="操作" >
     <template v-slot="{row}" >
        <el-button @click="del(row.id)"  type="text" size="small">删除</el-button>

      </template>
     </el-table-column>

     </el-table>
    </el-card>
  </div>
</template>

<script>
import { getArticles } from '@/api/article'
export default {
  name: 'article-page',
  data () {
    return {
      q: {
        current: 1,
        pageSize: 10
      },
      list: [],
      total: 0

    }
  },
  async created () {
    const res = await getArticles(this.q)
    console.log(res)
    this.list = res.data.rows
    this.rotal = res.data.pagetotal
  },
  methods: {
    del (id) {
      // console.log(id)
      const index = this.list.findIndex(item => item.id === id)
      // console.log(index)
      this.list.splice(index, 1)
    }
  }
}
</script>

<style lang="scss" scoped>
.el-card {
  margin-top: 25px;
  .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-right: 16px;
  }
  .actions {
    font-size: 18px;
    display: flex;
    justify-content: space-around;
    color: #666;
    > i:hover {
      color: rgba(114, 124, 245, 1);
      cursor: pointer;
    }
  }
}
.el-pagination {
  margin-top: 20px;
  text-align: center;
}
.el-breadcrumb {
  margin-top: 10px;
}
.el-form {
  padding-right: 40px;
}
.quill-editor {
  ::v-deep .ql-editor {
    height: 300px;
  }
}
.el-rate {
  padding: 10px 0;
}
.article-preview {
  padding: 0 40px 40px 40px;
  > h5 {
    font-size: 20px;
    color: #666;
    border-bottom: 1px dashed #ccc;
    padding-bottom: 30px;
    margin: 0 0 20px 0;
  }
}
</style>
